package com.finance.aop;

import com.finance.framework.shiro.ShiroConfig;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Arrays;

/**
 * Created by CBWL on 2017/4/28.
 */
@Component
@Aspect
public class AccessAop {
    Logger logger = LoggerFactory.getLogger(this.getClass());

    @Resource
    private ShiroConfig shiroConfig;

    @After("execution(public * add(..)) && this(com.finance.system.service.IMenuService)" )
    public void afterMenuAdd(JoinPoint jp){
        this.logger.info(Arrays.toString(jp.getArgs()));
        this.shiroConfig.reload();
    }

    @After("execution(public * update*(..)) && this(com.finance.system.service.IMenuService)" )
     public void afterMenuUpdate(JoinPoint jp){
        this.logger.info(Arrays.toString(jp.getArgs()));
        this.shiroConfig.reload();
    }

    @After("execution(public * del(..)) && this(com.finance.system.service.IMenuService)" )
     public void afterMenuDel(JoinPoint jp){
        this.logger.info(Arrays.toString(jp.getArgs()));
        this.shiroConfig.reload();
    }

    @After("execution(public * add*(..)) && this(com.finance.system.service.IRoleService)" )
     public void afterRoleAdd(JoinPoint jp){
        this.logger.info(Arrays.toString(jp.getArgs()));
        this.shiroConfig.reload();
    }

    @After("execution(public * update*(..)) && this(com.finance.system.service.IRoleService)" )
    public void afterRoleUpdate(JoinPoint jp){
        this.logger.info(Arrays.toString(jp.getArgs()));
        this.shiroConfig.reload();
    }

    @After("execution(public * del*(..)) && this(com.finance.system.service.IRoleService)" )
    public void afterRoleDel(JoinPoint jp){
        this.logger.info(Arrays.toString(jp.getArgs()));
        this.shiroConfig.reload();
    }

    @After("execution(public * mod*(..)) & this(com.finance.system.service.IRoleService)" )
    public void afterRoleModify(JoinPoint jp){
        this.logger.info(Arrays.toString(jp.getArgs()));
        this.shiroConfig.reload();
    }

    @After("execution(public * batch*(..)) & this(com.finance.system.service.IRoleService)" )
     public void afterRoleBatch(JoinPoint jp){
        this.logger.info(Arrays.toString(jp.getArgs()));
        this.shiroConfig.reload();
    }

}
